﻿using AutoMapper;
using KayakMes.Common.Dtos.ProductControlDTO.Input;
using KayakMes.Common.Dtos.ProductControlDTO.Output;
using KayakMes.Common.Result;
using KayakMes.ProductControl.Application.Services;
using KayakMes.ProductControl.Domain.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yitter.IdGenerator;

namespace KayakMes.ProductControl.API.Controllers
{
    /// <summary>
    /// 产品管理—规格控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SpecificationController : ControllerBase
    {
        private readonly IProductService productService;

        public SpecificationController(IProductService productService)
        {
            this.productService = productService;
        }
        /// <summary>
        /// 添加规格信息
        /// </summary>
        /// <param name="input">规格实体输入参数</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public ApiResult<int> AddSpecification(AddSpecificationInput input)
        {
            return productService.AddSpecification(input);
        }
        /// <summary>
        /// 获取规格所有信息
        /// </summary>
        /// <param name="input">获取规格信息输入参数</param>
        /// <returns>返回受影响行数</returns>
        [HttpGet]
        public ApiPaging<SpecificationOutput> GetAllSpecification([FromQuery]GetSpecificationInput input)
        {
            return productService.GetAllSpecification(input);
        }
        /// <summary>
        /// 根据指定Id获取规格信息
        /// </summary>
        /// <param name="Id">指定规格Id</param>
        /// <returns>返回受影响行数</returns>
        [HttpGet]
        public ApiResult<SpecificationOutput> GetSpecificationCount([FromQuery]long Id)
        {
            return productService.GetSpecificationCount(Id);
        }
        /// <summary>
        /// 更新规格信息
        /// </summary>
        /// <param name="specification">规格实体参数</param>
        /// <returns>返回受影响行数</returns>
        [HttpPut]
        public ApiResult<int> UpdateSpecification(SpecificationOutput specification)
        {
            return productService.UpdateSpecification(specification);
        }
        /// <summary>
        /// 删除规格信息
        /// </summary>
        /// <param name="Id">规格信息Id</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public ApiResult<int> DelSpecification(long Id)
        {
            return productService.DelSpecification(Id);
        }
    }
}
